package com.google.code.jtasks.common.data;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;


/**
 * User date class
 */
public class User {
    public final Optional<String> id;
    public final String name;
    public final String password;

    public User(String name, String password) {
        this.id = Optional.absent();
        this.name = name;
        this.password = password;
    }

    @JsonCreator
    public User(@JsonProperty("id") Optional<String> id,
                @JsonProperty("name") String name,
                @JsonProperty("password") String password) {
        this.id = id;
        this.name = name;
        this.password = password;

    }

    public User withId(String id) {
        return new User(Optional.of(id), this.name, this.password);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        User user = (User) o;

        return id.equals(user.id) &&
                name.equals(user.name) && password.equals(user.password);
    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + password.hashCode();
        return result;
    }
}
